package com.school.movie.business.web.controller;

import com.school.movie.business.web.model.vo.MovieActorVo;
import com.school.movie.business.web.model.vo.OrderVo;
import com.school.movie.business.web.model.vo.PlanVo;
import com.school.movie.business.web.model.vo.UserVo;
import com.school.movie.common.bean.ActorTypeBeanVo;
import com.school.movie.common.utils.BaseConstants;
import com.school.movie.service.imp.OrderServiceImpl;
import com.school.movie.service.imp.SysLogServiceImp;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 抽取公共方法的抽象父类
 *
 * @author swift
 */
public abstract class BaseController {


    protected UserVo getMember(HttpSession session) {
        return (UserVo) session.getAttribute("member");
    }

    protected void actorList2ActorTypeList(List<MovieActorVo> actorList, List<ActorTypeBeanVo> actorBeanList) {
        int actorType = 0;
        ActorTypeBeanVo act = null;
        for (MovieActorVo actor : actorList) {
            if (actorType == 0) {
                act = new ActorTypeBeanVo();
                act.setActorTypeId(actor.getActorType());
                act.setActorTypeName(actor.getActorTypeName());
            } else if (actorType != actor.getActorType()) {
                actorBeanList.add(act);
                act = new ActorTypeBeanVo();
                act.setActorTypeId(actor.getActorType());
                act.setActorTypeName(actor.getActorTypeName());
            }
            act.getActorList().add(actor);
            actorType = actor.getActorType();
        }
    }

    protected void insertNewOrder(OrderServiceImpl orderService, SysLogServiceImp logService, int planId, String payType, UserVo user, PlanVo plan, String s, long orderId) {
        OrderVo order = new OrderVo();
        order.setPlanId(planId);
        order.setHallSeatId(Integer.parseInt(s));
        order.setSalePrice(plan.getSeatPrice());
        order.setMobile(user.getMobile());
        order.setPayType(payType);
        order.setState("已购票");
        order.setOrderId(orderId);
        orderService.add(order);
        logService.add(BaseConstants.LOG_ADD, order.toString());
    }


}
